<?php
/**
 * desc Created by wang.
 * User: wang
 * motto: 是时候为小时候吹过的牛而努力了!
 * Date: 2020/3/23 16:38
 */

namespace app\common\model\mysql;


use think\Model;

class Auth extends Model
{
    protected $name = 'auth_rule';
    protected $autoWriteTimestamp = true;


    /**
     * 功能说明 通过ID更新数据
     * @author: wang
     * @Date: 2020/3/24 18:17
     * @param $id
     * @param $data
     * @return bool
     */
    public function edit($id, $data)
    {
        $where[] = ['id', '=', $id];
        return $this->where($where)->save($data);
    }

    /**
     * 功能说明 通ID获取数据
     * @author: wang
     * @Date: 2020/3/23 16:42
     * @param $title
     * @return array|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getDataById($id)
    {
        $where[] = ['id', '=', $id];
        return $this->where($where)->find();
    }

    /**
     * 功能说明 获取权限列表
     * @author: wang
     * @Date: 2020/3/24 16:41
     * @param $limit
     * @return \think\Paginator
     * @throws \think\db\exception\DbException
     */
    public function getAuthList($limit)
    {
        return $this->order('sort asc')->paginate($limit);
    }

    /**
     * 功能说明 通过ID更新排序
     * @author: wang
     * @Date: 2020/3/24 16:45
     * @param $data
     * @return bool
     */
    public function upSort($data)
    {
        $where[] = ['id', '=', $data['id']];
        $saveData = [
            'sort' => $data['sort']
        ];
        return $this->where($where)->save($saveData);
    }

    /**
     * 功能说明 通过ID删除数据
     * @author: wang
     * @Date: 2020/3/24 18:18
     * @param $id
     * @return bool
     */
    public function delDataById($id)
    {
        return (new Auth())::destroy($id);
    }

    /**
     * 功能说明 通过权限Ids 获取个人全部权限
     * @author: wang
     * @Date: 2020/4/1 12:26
     * @param $ids
     */
    public function getAuthByIds($ids)
    {
        $where[] = ['id', 'in', $ids];
        return $this->where($where)->select();
    }
}